//
//  hitTestViewController.m
//  runtimeStudy
//
//  Created by PF on 2022/9/14.
//

#import "hitTestViewController.h"

@interface hitTestViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *_dataArray;
}
@end

@implementation hitTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds];
    tableView.delegate = self;
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    _dataArray = @[@"内存大小",
                   @"kvo",
                   @"kvc",
                   @"block",
                   @"多线程相关（gcd、operation、锁）",
                   @"SDWebImage源码",
                   @"属性关键字copy，与深复制、浅复制",
                   @"load方法与initialize方法的区别和作用",
                   @"归档NSKeyedArchiver与NSCoding协议",
                   @"NSNotification",
    ];
    
}
 
-(void)dealloc{
    NSLog(@"dealloc");
}
 

# pragma mark - tableview
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}
static NSString *cellIdentfier = @"Cell";
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentfier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentfier];
    }
    cell.textLabel.text = [_dataArray objectAtIndex:indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    SEL sel = NSSelectorFromString([NSString stringWithFormat:@"test%ld",(indexPath.row+1)]);
    //解决 编译警告PerformSelector may cause a leak because its selector is unknown
    IMP imp = [self methodForSelector:sel];
    void (*func) (id, SEL) = (void *)imp;
    if ([self respondsToSelector:sel]) {
        func(self, sel);
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}
@end
